// 主席树 树上路径点权第 k 小
// https://soj.turingedu.cn/course/14/contest/9/problem/3
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 2e5;

struct Segtree {
    int tot;
    int val[maxn << 5];
    int ch[maxn << 5][2];
    inline int new_node(int x) { return val[++tot] = x, ch[tot][0] = 0, ch[tot][1] = 0, tot; }
    inline void maintain(int u) { val[u] = val[ch[u][0]] + val[ch[u][1]]; }
    inline int cp(int u) { return val[++tot] = val[u], ch[tot][0] = ch[u][0], ch[tot][1] = ch[u][1], tot; }
    int build(int l, int r) {
        int u = new_node(0);
        if (l == r) return u;
        int mid = l + r >> 1;
        ch[u][0] = build(l, mid);
        ch[u][1] = build(mid + 1, r);
        return u;
    }
    int update(int u, int l, int r, int pos, int x) {
        u = cp(u);
        if (l == r) {
            val[u] += x;
            return u;
        }

        int mid = l + r >> 1;
        if (pos <= mid)
            ch[u][0] = update(ch[u][0], l, mid, pos, x);
        else
            ch[u][1] = update(ch[u][1], mid + 1, r, pos, x);
        maintain(u);
        return u;
    }
    int ask(int u, int v, int Lca, int Fa, int l, int r, int k) {
        if (l == r) return l;
        int mid = l + r >> 1;
        int cnt = val[ch[u][0]] + val[ch[v][0]] - val[ch[Lca][0]] - val[ch[Fa][0]];
        if (cnt >= k)
            return ask(ch[u][0], ch[v][0], ch[Lca][0], ch[Fa][0], l, mid, k);
        else
            return ask(ch[u][1], ch[v][1], ch[Lca][1], ch[Fa][1], mid + 1, r, k - cnt);
    }
} sg;
int root[maxn], rsiz;

int n, m;
vector<int> adj[maxn];
int a[maxn];
int dsiz, decoder[maxn];
void init_decoder() {
    dsiz = n;
    rf(i, n) decoder[i] = a[i];
    sort(decoder + 1, decoder + 1 + dsiz);
    dsiz = unique(decoder + 1, decoder + 1 + dsiz) - decoder - 1; // 注意减 1
}
inline int coder(int x) { return lower_bound(decoder + 1, decoder + 1 + dsiz, x) - decoder; }

int fa[maxn][21], dep[maxn];
void dfs(int u, int p) {
    dep[u] = dep[p] + 1, fa[u][0] = p;
    rf(j, 20) fa[u][j] = fa[fa[u][j - 1]][j - 1];
    root[u] = sg.update(root[p], 1, dsiz, coder(a[u]), 1);
    for (auto v : adj[u])
        if (v != p) dfs(v, u);
}
int lca(int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    for (int ed = dep[u] - dep[v], j = 0; ed > 0; ++j, ed >>= 1)
        if (ed & 1) u = fa[u][j];
    if (u == v) return u;
    for (int j = 20; j >= 0; --j)
        if (fa[u][j] != fa[v][j]) u = fa[u][j], v = fa[v][j];
    return fa[u][0];
}

int main() {
    // freopen("main.in", "r", stdin);
    // freopen("main.out", "w", stdout);
    n = rad();
    rf(i, n) a[i] = rad();
    rf(i, n - 1) {
        int l = rad(), r = rad();
        adj[l].push_back(r), adj[r].push_back(l);
    }

    init_decoder();
    root[0] = sg.build(1, dsiz);
    dfs(1, 0);

    m = rad();
    rf(i, m) {
        int u = rad(), v = rad(), k = rad();
        int Lca = lca(u, v), Fa = fa[Lca][0];
        printf("%d\n", decoder[sg.ask(root[u], root[v], root[Lca], root[Fa], 1, dsiz, k)]);
    }
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}